package rursu.http;

import java.io.IOException;
import java.io.InputStream;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

public class HttpClientManager {
	
	private static HttpClient client = new DefaultHttpClient();
	
	public static synchronized HttpClient getHttpClient() {
		return client;
	}
	
	public static synchronized InputStream getInputStream(String url) {
		InputStream input = null;
		
		if ( url != null ) {
			HttpGet getRequest = new HttpGet(url);
			
			HttpResponse response;
			try {
				
				response = HttpClientManager.getHttpClient().execute(getRequest);
				input = response.getEntity().getContent();
				
			} catch (ClientProtocolException e) {
				
				e.printStackTrace();
				
			} catch (IOException e) {
				
				e.printStackTrace();
			}
			
		}
		
		return input;
	}
	
}
